/**
 * @created by zhangpeng18 on 2019-8-5 10:40:22
 * @updated by
 * @description Java类驱动管理
 */
define(['./custom/widgets/js/yufpSelectParam.js'],
  function (require, exports) {
    /**
     * 页面加载完成时触发
     * @param hashCode 路由ID
     * @param data 传递数据对象
     * @param cite 页面站点信息
     */
    exports.ready = function (hashCode, data, cite) {
      yufp.custom.vue({
        el: cite.el,
        data: function () {
          var _this = this;
          var eventTypeOption = [{
            key: 'G',
            value: '普通事件'
          },
          {
            key: 'F',
            value: '文件事件'
          }
          ]
          /*定义校验规则，只能填字母数字 下划线*/
          var valiCodes = function (rule, value, callback) {
            var reg = /^[0-9a-zA-Z_]{1,}$/;
            if (value && reg.test(value)) {
              if (value.length > 64) {
                callback(new Error('长度不能大于64位'));
              } else {
                callback();
              }
            } else if (value && !reg.test(value)) {
              callback(new Error('能填字母、数字和下划线'));
            } else {
              callback();
            }
          };
          return {
			tbHeight:'0',
            upLoadDialogVisible: false, //是否显示导入页面
            upLoadUrl: yufp.service.getUrl({
              url: "api/file/provider/uploadfile"
            }), //导入的url
            appUploadDatas: [], //文件列表
            showHeader: false, //是否显示错误表头
            errshow: false, //显示导入的错误信息，默认不显示
            excelloading: false, //导入的loading
            errdata: [
              /* 						{'errMsg':'第7行的参数类型不合法'},
              						{'errMsg':'第7行的参数类型不合法'},
              						{'errMsg':'第7行的参数类型不合法'},
              						{'errMsg':'第7行的参数类型不合法'},
              						{'errMsg':'第7行的参数类型不合法'},
              						{'errMsg':'第7行的参数类型不合法'},
              						{'errMsg':'第7行的参数类型不合法'} */
            ], //导入的错误信息
            searchFormdata: {},
            appNameDisabled: false,
            eventNameDisabled: false,
            addFnButton: !yufp.session.checkCtrl('addFn'),
            updateFnButton: !yufp.session.checkCtrl('updateFn'),
            deleteFnButton: !yufp.session.checkCtrl('deleteFn'),
            importFnButton: !yufp.session.checkCtrl('importFn'),
            exportFnButton: !yufp.session.checkCtrl('exportFn'),
            addClassFnButton: !yufp.session.checkCtrl('addClassFn'),
            updateClassFnButton: !yufp.session.checkCtrl('updateClassFn'),
            deleteClassFnButton: !yufp.session.checkCtrl('deleteClassFn'),
            multipleFalg: false, //是否允许多文件
            treeDataUrl: "api/use/plats/event/queryTreeList",
            dataUrl: 'api/use/plats/event/queryList',
            saveBtnShow: true,
            cancelBtnShow: true,
            addBtnShow: false,
            formdata: {},
            formdataRemark: {},
            async: false,
            height: yufp.frame.size().height - 147,
            folderHeight: 300,
            dialogVisible: false,
            formDisabled: false,
            classCodeDisabled: false,
            viewTitleArrry: ['事件添加', '事件修改', '事件查看'],
            viewTitle: '',
            propTabaleData: [],
            eventTypeOption: eventTypeOption,
            appCodeShow: true,
            appShowName: "",
            nodeData: '', // 在新增表格数据时需要先获取当前树节点，再把一条新的记录加到这个节点下的表格里,
            nodeLeaf: false,
            isDisabledAppName: false,
            isReadOnly: false,
            isAppNode: false,
            isNodeLeaf: false,
            nodeLeafData: {},
            dataSources: [],
            currentClickNode: {},
            defaultFolderKey: [],
            isClassaddFlag: false,
            classCodeReadOnly: false,
            chooseFolderDialogVisible: false,
            isFileEvent: false,
            currAppNode: {},
            agentIds: [],
            filDatas: [],
            viewClassTitle: "",
            folderRoot: "",
            isAdd: false,
            paramObj: {
              addEnd: true
            },
            viewClassTitleArrry: ['事件目录信息添加', '事件目录信息修改'],
            isView: false,
            classDialogVisible: false,
            currAppCode: "",
            paramValueValidate: [{
              required: true,
              message: '必填项',
              trigger: 'blur'
            },
            {
              message: '请输入数字',
              validator: yufp.validator.number
            }
            ],
            ruleslist: {
              eventCode: [{
                validator: valiCodes,
                trigger: 'blur'
              }]
            },
            classFields: [{
              columnCount: 2,
              fields: [{
                field: 'appCode',
                label: '所属应用系统编号:',
                hidden: true
              },
              {
                field: 'appName',
                label: '所属应用系统:',
                disabled: true
              },
              {
                field: 'parentFolder',
                label: '上级目录名称:',
                hidden: true
              },
              {
                field: 'parentFolderName',
                label: '上级目录名称:',
                disabled: true
              }

              ]

            }, {
              columnCount: 2,
              fields: [{
                field: 'folderCode',
                label: '目录代码:',
                readOnly: false,
                maxlength: 64,
                rules: [{
                  validator: valiCodes,
                  trigger: 'blur'
                }]
                // hidden: true
              },
              {
                field: 'folderName',
                label: '目录名称:',
                maxlength: 120,
                rules: [{
                  required: true,
                  message: '必填项',
                  trigger: 'blur'
                },
                {
                  max: 120,
                  message: '输入值过长',
                  trigger: 'blur'
                }
                ]
              }
              ]
            }, {
              columnCount: 1,
              fields: [{
                field: 'remark',
                label: '备注:',
                type: "textarea",
                rows: 3,
                maxlength: 240,
                rules: [{
                  max: 256,
                  message: '输入值过长',
                  trigger: 'blur'
                }]
              }]
            }],

            classButtons: [{
              label: '取消',
              hidden: false,
              click: function (model) {
                _this.cancelClassFn();
              }
            },
            {
              label: '保存',
              type: 'primary',
              hidden: false,
              op: 'submit',
              click: function (model, valid) {
                _this.saveClassCodeFn();
              }
            }
            ],

            queryName: "",
            tableColumns: [{
              label: '序号',
              type: "index"
            },
            {
              label: '系统名称',
              prop: 'appName',
              hidden: false
            },
            {
              label: '事件路径',
              prop: 'folderPath'
            },
            {
              label: '事件代码',
              prop: 'eventCode',
              template: function () {

                return '<template scope="scope">\
															 <a style="text-decoration:underline;color:#636CE4 " href="javascipt:void(0);"  @click="_$event(\'custom-detail-click\', scope.row)">{{ scope.row.eventCode }}</a>\
													 </template>';
              }
            },
            {
              label: '事件名称',
              prop: 'eventName',
              /*  template:function(){
                              return  '<template scope="scope">\
                             <a style="text-decoration:underline;color:#636CE4 " href="javascipt:void(0);"  @click="_$event(\'custom-detail-click\', scope.row)">{{ scope.row.eventCode }}</a>\
                         </template>';
                      }*/
            },
            {
              label: '事件类型',
              prop: 'eventType',
              dataCode: 'USE_EVENT_TYPE'
            },
            {
              label: '备注',
              prop: 'remark'
            }
            ],
            //isReadOnly: false,
            nodeTemp: {},
            exportLoading: false
          };
        },
		mounted:function(){
			var _this = this;
			//测试
			_this.$nextTick(function(){
					var tableBox = _this.$refs.tableBox;
					let a = tableBox.getBoundingClientRect().top + 28;
					var theight = `calc(100vh - ${a}px - 64px)`;
					_this.tbHeight = theight;		
			});
		},
        methods: {
          //点击导出模板操作
          exportDemo: function () {
            var _this = this;
            var condition = { busiType: "EVENT" };
            var search = _this.searchFormdata;
            yufp.util.download("api/use/excel/exportTempExcel?condition="
              + encodeURI(JSON.stringify(condition)));
          },
          //点击导出操作
          exportFlowFn: function () {
            var _this = this;
            var condition = { busiType: "EVENT" };
            var search = _this.searchFormdata;
            condition.appName = search.appName;
            condition.eventName = search.eventName;
            condition.eventType = search.eventType;

            var selectDatas = _this.$refs.refTable.selections;

            if (selectDatas.length > 0) {
              condition.dataList = selectDatas;
            }

            _this.exportLoading = true;
            yufp.service.request({
			  method: 'POST',
			  url: '/api/use/excel/exportExcelForWeb',
              data: { condition: condition },
              callback: function (code, message, response) {
                _this.exportLoading = false;
                if (response.code === 0) {
                  yufp.util.download("api/use/excel/downLoadExcel?filePath=" + response.data.allFilePath + "&fileName=" + response.data.fileName);
                } else {
                  this.$message.error('导出失败');
                }
              }
            });
          },
          importFlowFn: function () { //点击导入操作
            this.upLoadDialogVisible = true;
            this.$nextTick(function () {
              this.$refs['my-upload'].clearFiles();
              this.errshow = false;
              this.errdata = [];
            })
          },
          /**
           *导入前的检验操作操作
           */
          checkUpload: function (file) {
            //alert(file);

            var isLt10M = file.size / 1024 / 1024 < 100;
            if (!isLt10M) {
              this.$message.error('上传文件大小不能超过 100MB!');
            }
            var index = file.name.lastIndexOf('.');
            var ext = file.name.substr(index + 1);

            var suffixValid = ('xlsx' === ext || 'xls' === ext);
            if (!suffixValid) {
              this.$message.error('上传文件的格式必须为excel格式');
              return false;
            }
            return isLt10M && suffixValid;
          },
          successUpload: function (response, file, fileList) { //导入成功后执行
            /*	console.log('上传成功！')
            	this.$refs['my-upload'].clearFiles();*/


            const _this = this;
            const param = {};
            /* 					_this.$loading({
            						target:'.load-target',
            						body:true
            					}) */
            _this.excelloading = true;
            param.busiType = "EVENT";
            param.excelUpLoadFile = response.data;
            yufp.service.request({
              method: 'POST',
              url: '/api/use/excel/importExcel',
              data: param,
              timeout: 1800000,
              callback: function (code, message, response) {
                _this.excelloading = false;
                if (response.code == 0 && response.data.errorInfos.length == 0 && response.data.impStatus !=
                  '失败') {
                  _this.$refs['my-upload'].clearFiles();
                  _this.errshow = false;
                  _this.errdata = [];
                  _this.upLoadDialogVisible = false;
                  _this.$message('导入成功!');
                  //同时重新查询列表

                  var param = {
                    condition: JSON.stringify(_this.searchFormdata)
                  };
                  _this.$refs.refTable.remoteData(param);

                } else {
                  _this.errshow = true;
                  _this.$refs['my-upload'].clearFiles();
                  _this.errdata = [];
                  if (response.data && response.data.errorInfos.length > 0 && response.data.errorInfos[
                    0].errorList) {
                    response.data.errorInfos[0].errorList.map(function (item, index) {
                      _this.errdata.push({
                        "errMsg": item
                      })
                      console.log('errdata', _this.errdata)
                    })
                  } else {
                    _this.errdata.push({
                      "errMsg": response.message
                    })
                  }

                }
              }
            });
          },
          loadData: function () {
            var _this = this;
            var param = {
              condition: JSON.stringify(_this.searchFormdata)
            };
            _this.$refs.refTable.remoteData(param);

          },

          getSelectedData: function (data) {
            var _this = this;
            _this.$refs.refFiletab.selections[0].pathName = '{#' + data[0].paramValue + '#}';
          },

          createTreeFn: function () {
            var _this = this;
            if (_this.currentClickNode == null ||
              _this.currentClickNode.nodeType == null ||
              _this.currentClickNode.nodeType === 'R') {
              _this.$message("请选择一个应用系统或目录");
              return;
            }
            _this.classDialogVisible = true;
            _this.viewClassTitle = _this.viewClassTitleArrry[0];
            _this.isClassaddFlag = true;
            //_this.$set( _this.classFields[1].fields[0], 'readonly',  false);
            /* _this.classCodeReadOnly = false;
             _this.$set(_this.classFields[0].fields[2], 'readonly',  _this.classCodeReadOnly );*/
            _this.$nextTick(function () {
              _this.$refs.refClassForm.switch(_this.classFields[1].fields[0].field, 'disabled', false);
              _this.$refs.refClassForm.resetFields();
              _this.$refs.refClassForm.formModel.appCode = _this.currentClickNode.appCode;
              _this.$refs.refClassForm.formModel.appName = _this.currentClickNode.appName;

              if (_this.currentClickNode.nodeType === 'A') {
                _this.$refs.refClassForm.formModel.parentFolder = " ";
                _this.$refs.refClassForm.formModel.parentFolderName = "事件分层主目录";
              } else {
                _this.$refs.refClassForm.formModel.parentFolder = _this.currentClickNode.currentNodeId;
                _this.$refs.refClassForm.formModel.parentFolderName = _this.currentClickNode.currentNodeName;
              }


            });

          },
          cancelClassFn: function () {
            var _this = this;
            this.classDialogVisible = false;
          },

          selectFolder: function () {
            var _this = this;
            if (_this.addFlag) {
              _this.folderRoot = _this.currentClickNode.appCode;
            } else {
              _this.folderRoot = _this.$refs.refTable.selections[0].appCode;
            }

            _this.defaultFolderKey.splice(0);
            if (_this.formdata.folderCode != null) {
              _this.defaultFolderKey.push(_this.formdata.folderCode);

            }

            _this.chooseFolderDialogVisible = true;
            _this.$nextTick(function () {
              _this.$refs.refFolderTree.remoteData({});
            });

          },

          saveClassCodeFn: function () {

            var _this = this;
            var validate = false;
            _this.$refs.refClassForm.validate(function (valid) {
              validate = valid;
            });
            if (!validate) {
              return;
            }

            let urlparam = "";

            if (_this.isClassaddFlag) {
              urlparam = 'api/use/plats/event/saveUseEventCatalog';
            } else {
              urlparam = 'api/use/plats/event/updateUseEventCatalog';
            }

            yufp.service.request({
              method: 'POST',
              url: urlparam,
              data: _this.$refs.refClassForm.formModel,
              callback: function (code, message, response) {

                if (response.code == 0) {
                  _this.$message('操作成功');
                  _this.classDialogVisible = false;
                  _this.$refs.refTree.remoteData({});
                  _this.loadData();
                } else {
                  _this.$message(response.message);
                }
              }
            });

          },


          updateTreeFn: function () {
            var _this = this;

            if (_this.currentClickNode.nodeType != 'C') {
              _this.$message({
                message: "请选择一个事件目录",
                type: "warning"
              });
              return;
            }
            // _this.classFields[1].fields[0].readOnly= true;
            //_this.$set( _this.classFields[1].fields[0], 'readonly',  true);

            _this.classDialogVisible = true;
            _this.viewClassTitle = _this.viewClassTitleArrry[1];
            _this.isClassaddFlag = false;
            _this.classCodeReadOnly = true;
            _this.$nextTick(function () {
              _this.$refs.refClassForm.switch(_this.classFields[1].fields[0].field, 'disabled', true);
              _this.$refs.refClassForm.resetFields();
              _this.$refs.refClassForm.formModel.appCode = _this.currentClickNode.appCode;
              _this.$refs.refClassForm.formModel.appName = _this.currentClickNode.appName;
              _this.$refs.refClassForm.formModel.parentFolder = _this.currentClickNode.parentId;
              _this.$refs.refClassForm.formModel.parentFolderName = _this.currentClickNode.parentName;
              _this.$refs.refClassForm.formModel.folderCode = _this.currentClickNode.currentNodeId;
              _this.$refs.refClassForm.formModel.folderName = _this.currentClickNode.currentNodeName;
              _this.$refs.refClassForm.formModel.remark = _this.currentClickNode.remark;
            });

          },
          deleteTreeFn: function () {
            var _this = this;

            if (_this.currentClickNode.nodeType != 'C') {
              _this.$message({
                message: "请选择一个事件目录",
                type: "warning"
              });
              return;
            }
            _this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning',
              duration: 6000,
              center: true,
              callback: function (action) {
                if (action === 'confirm') {
                  let paramObj = {};
                  paramObj.appCode = _this.currentClickNode.appCode;
                  paramObj.folderCode = _this.currentClickNode.currentNodeId;

                  yufp.service.request({
                    method: 'DELETE',
                    url: "api/use/plats/event/deleteUseEventCatalog",
                    data: paramObj,
                    callback: function (code, message, response) {
                      if (response.code != 0) {
                        _this.$message({
                          message: response.message,
                          type: "warning"
                        });
                      } else {
                        _this.$message('操作成功');
                        _this.$refs.refTree.remoteData({});
                        var paramObject = {};
                        paramObject.appCode = _this.currentClickNode.appCode;
                        _this.$refs.refTable.remoteData({
                          condition: paramObject
                        });
                      }

                    }
                  });
                }
              }
            });
          },


          /*改变事件信息*/
          changeEventType: function (val) {
            var _this = this;
            if (val === 'F') {
              //_this.queryWftAgtList();
              _this.isFileEvent = true;
            } else {
              _this.isFileEvent = false;
            }

          },

          /**
           * 取消
           */
          cancelFn: function () {
            var _this = this;
            _this.dialogVisible = false;
          },
          /**
           * 保存
           */
          saveFn: function () {
            var _this = this;
            var validate = false;
            _this.$refs.refForm.validate(function (valid) {
              validate = valid;
            });
            if (!validate) {
              return;
            }
            var paramObj = _this.$refs.refForm.formdata;
            if (paramObj.eventType === 'F') {
              if (_this.filDatas.length == 0) {
                _this.$message({
                  message: "至少输入一个文件路径",
                  type: "warning"
                });
                return;
              } else {
                for (let i = 0; i < _this.filDatas.length; i++) {
                  if (_this.filDatas[i].pathName == null || _this.filDatas[i].pathName == '') {
                    _this.$message({
                      message: "文件路径不能为空",
                      type: "warning"
                    });
                    return;
                  }
                }
              }
              paramObj.useEventFiles = _this.filDatas;
            } else {
              if (paramObj.agentCode == null || paramObj.agentCode == '') {
                paramObj.agentCode = " ";
              }
            }
            paramObj.remark = _this.$refs.refFormMark.formdata.remark;
            let urlparam = "";
            if (_this.addFlag) {
              urlparam = 'api/use/plats/event/saveUseEventInfo';
            } else {
              urlparam = 'api/use/plats/event/updateUseEventInfo';
            }
            yufp.service.request({
              method: 'POST',
              url: urlparam,
              data: paramObj,
              callback: function (code, message, response) {
                if (response.code == 0) {
                  _this.loadData();
                  _this.$message('操作成功');
                  _this.dialogVisible = false;
                } else {
                  _this.$message({
                    message: response.message,
                    type: "warning"
                  });
                }
              }
            });





          },
          /**
           * 控制保存按钮、xdialog、表单的状态
           * @param viewType 表单类型
           * @param editable 可编辑,默认false
           */
          switchStatus: function (viewType, editable) {
            var _this = this;
            _this.viewType = viewType;
            _this.dialogVisible = true;
            _this.formDisabled = !editable;
            _this.saveBtnShow = editable;
            _this.cancelBtnShow = editable;
          },




          folderNodeClickFn: function (nodeData) {

            var checkObjects = this.$refs.refFolderTree.getCheckedNodes();
            for (var i = 0; i < checkObjects.length; i++) {
              if (nodeData.currentNodeId === checkObjects[i].currentNodeId) {
                continue;
              } else {
                this.$refs.refFolderTree.setChecked(checkObjects[i], false);
              }
            }

          },

          selectFolderSaveFn: function () {
            var _this = this;
            var checkObjects = this.$refs.refFolderTree.getCheckedNodes();
            if (checkObjects.length != 1) {
              _this.$message({
                message: '请先选择一条记录',
                type: 'warning'
              });
              return;
            } else {
              if (checkObjects[0].nodeType === 'A') {
                _this.formdata.folderCode = '';
              } else {
                _this.formdata.folderCode = checkObjects[0].currentNodeId;
              }
              _this.formdata.folderName = checkObjects[0].currentNodeName;
              _this.chooseFolderDialogVisible = false;
            }
          },

          selectFolderCancelFn: function () {
            var _this = this;
            var checkObjects = this.$refs.refFolderTree.getCheckedNodes();
            for (var i = 0; i < checkObjects.length; i++) {
              this.$refs.refFolderTree.setChecked(checkObjects[i], false);
            }

            _this.chooseFolderDialogVisible = false;
          },

          /**
           * 点击树的结点，加载对应的数据
           */
          nodeClickFn: function (nodeData, node, self) {
            var _this = this;
            _this.currentClickNode = nodeData;
            let appCode = "";
            let folderCode = "";

            if (nodeData.nodeType != 'R') {
              _this.isNodeLeaf = true;
              _this.tableColumns[1].hidden = true;
              _this.appNameDisabled = true;
              _this.searchFormdata.appName = nodeData.appName;
              appCode = nodeData.appCode;
              _this.paramObj.appCode = nodeData.appCode;
              if (nodeData.nodeType === 'C') {
                folderCode = nodeData.currentNodeId
              }

            } else {
              _this.isNodeLeaf = false;
              _this.appNameDisabled = false
              _this.searchFormdata.appName = '';
              _this.tableColumns[1].hidden = false;
              _this.paramObj.appCode = "";
            }

            //var paramObj = {};
            _this.searchFormdata.appCode = appCode;
            _this.searchFormdata.folderCode = folderCode;
            var param = {
              condition: JSON.stringify(_this.searchFormdata)
            };
            _this.$refs.refTable.remoteData(param);

          },
          /**
           * 新增
           */
          addFn: function () {
            var _this = this;
            _this.viewTitle = _this.viewTitleArrry[0];
            _this.addFlag = true;
            _this.isReadOnly = false;
            _this.isFileEvent = false;
            _this.dialogVisible = true;
            _this.isAdd = true;
            _this.isView = false;
            _this.currAppCode = _this.currentClickNode.appCode;

            _this.$nextTick(function () {
              _this.$refs.refForm.resetFields();
              _this.filDatas.splice(0);
              _this.$refs.refFormMark.resetFields();
              _this.formdata.appCode = _this.currentClickNode.appCode;
              if (_this.currentClickNode.currentNodeId === _this.currentClickNode.appCode) {
                _this.formdata.folderCode = _this.currentClickNode.currentNodeId;
                _this.formdata.folderName = "应用根目录";
              } else {
                _this.formdata.folderCode = _this.currentClickNode.currentNodeId;
                _this.formdata.folderName = _this.currentClickNode.currentNodeName;
              }

              yufp.service.request({
                method: 'GET',
                url: "api/use/plats/apps/queryWftAgtList",
                data: {
                  appCode: _this.currAppCode
                },
                async: false,
                callback: function (code, message, response) {
                  if (response.code != 0) {
                    _this.$message(response.message);
                  } else {
                    _this.agentIds.splice(0);
                    _this.agentIds.push({
                      key: " ",
                      value: "虚拟代理"
                    });
                    for (let i = 0; i < response.data.length; i++) {
                      _this.agentIds.push({
                        key: response.data[i].agentCode,
                        value: response.data[i].agentName
                      });
                    }
                  }

                }
              });


              /*  _this.formdata.appName = _this.nodeLeafData.parentName;
              	_this.formdata.className = _this.nodeLeafData.appName;
              	_this.formdata.paramType="C";*/

            });
          },

          viewDataFn: function (data) {
            var _this = this;
            _this.isAdd = false;
            _this.isView = true;
            _this.isReadOnly = true;
            _this.viewTitle = _this.viewTitleArrry[2];
            _this.dialogVisible = true;
            _this.paramObj.appCode = data.appCode;

            _this.addFlag = false;
            if (data.eventType === 'F') {
              _this.isFileEvent = true;
            } else {
              _this.isFileEvent = false;
            }

            _this.$nextTick(function () {
              // _this.$refs.refForm.;
              _this.filDatas.splice(0);
              //_this.$refs.refFormMark.resetFields();
              var paramObj = {};
              paramObj.appCode = data.appCode;

              yufp.service.request({
                method: 'GET',
                url: "api/use/plats/apps/queryWftAgtList",
                data: paramObj,
                async: false,
                callback: function (code, message, response) {
                  if (response.code != 0) {
                    _this.$message(response.message);
                  } else {
                    _this.agentIds.splice(0);
                    _this.agentIds.push({
                      key: " ",
                      value: "虚拟代理"
                    });
                    for (let i = 0; i < response.data.length; i++) {
                      _this.agentIds.push({
                        key: response.data[i].agentCode,
                        value: response.data[i].agentName
                      });
                    }
                    yufp.extend(_this.formdata, data);
                    yufp.extend(_this.formdataRemark, data);
                    if (data.eventType === 'F') {
                      if (data.useEventFiles != null &&
                        data.useEventFiles.length > 0) {
                        for (let i = 0; i < data.useEventFiles.length; i++) {
                          _this.filDatas.push(data.useEventFiles[i]);
                        }
                      }
                    }
                  }
                }
              });
            });
          },
          /**
           * 修改
           */
          modifyFn: function () {
            var _this = this;
            if (_this.$refs.refTable.selections.length != 1) {
              _this.$message({
                message: '请先选择一条记录',
                type: 'warning',
                duration:6000
              });
              return;
            }
            _this.isAdd = false;
            _this.isView = false;
            _this.isReadOnly = true;
            _this.viewTitle = _this.viewTitleArrry[1];
            _this.dialogVisible = true;
            _this.paramObj.appCode = _this.$refs.refTable.selections[0].appCode;
            _this.currAppCode = _this.$refs.refTable.selections[0].appCode;
            _this.addFlag = false;
            if (_this.$refs.refTable.selections[0].eventType === 'F') {
              _this.isFileEvent = true;
            } else {
              _this.isFileEvent = false;
            }

            _this.$nextTick(function () {
              // _this.$refs.refForm.;
              _this.filDatas.splice(0);
              //_this.$refs.refFormMark.resetFields();
              var paramObj = {};
              paramObj.appCode = _this.$refs.refTable.selections[0].appCode;

              yufp.service.request({
                method: 'GET',
                url: "api/use/plats/apps/queryWftAgtList",
                data: paramObj,
                async: false,
                callback: function (code, message, response) {
                  if (response.code != 0) {
                    _this.$message(response.message);
                  } else {
                    _this.agentIds.splice(0);
                    _this.agentIds.push({
                      key: " ",
                      value: "虚拟代理"
                    });
                    for (let i = 0; i < response.data.length; i++) {
                      _this.agentIds.push({
                        key: response.data[i].agentCode,
                        value: response.data[i].agentName
                      });
                    }
                    yufp.extend(_this.formdata, _this.$refs.refTable.selections[0]);
                    if (_this.formdata.folderName == null && _this.formdata.folderCode == _this.formdata
                      .appCode) {
                      _this.formdata.folderName = "应用根目录";
                    }
                    yufp.extend(_this.formdataRemark, _this.$refs.refTable.selections[0]);
                    if (_this.$refs.refTable.selections[0].eventType === 'F') {
                      if (_this.$refs.refTable.selections[0].useEventFiles != null &&
                        _this.$refs.refTable.selections[0].useEventFiles.length > 0) {
                        for (let i = 0; i < _this.$refs.refTable.selections[0].useEventFiles.length; i++) {
                          _this.filDatas.push(_this.$refs.refTable.selections[0].useEventFiles[i]);
                        }
                      }
                    }
                  }
                }
              });
            });
          },
          /**
           * 删除
           */
          deleteFn: function () {
            var _this = this;
            var selections = _this.$refs.refTable.selections;
            if (selections.length != 1) {
              _this.$message({
                message: '请先选择一条记录',
                type: 'warning',
                duration:6000,
              });
              return;
            }

            _this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning',
              duration:6000,
              center: true,
              callback: function (action) {
                if (action === 'confirm') {
                  yufp.service.request({
                    method: 'DELETE',
                    url: "api/use/plats/event/deleteUseEventInfo",
                    data: selections[0],
                    callback: function (code, message, response) {
                      if (response.code != 0) {
                        isOk = false;
                        _this.$message(response.message);
                      } else {

                        _this.loadData();
                        _this.$message('操作成功');
                        _this.dialogVisible = false;

                      }

                    }
                  });
                }
              }
            });
          },

          queryWftAgtList: function () {
            var _this = this;
            var paramObj = {};
            paramObj.appCode = _this.paramObj.appCod


            yufp.service.request({
              method: 'GET',
              url: "api/use/plats/apps/queryWftAgtList",
              data: paramObj,
              async: false,
              callback: function (code, message, response) {
                if (response.code != 0) {
                  isOk = false;
                  _this.$message(response.message);
                } else {
                  _this.agentIds.splice(0);
                  _this.agentIds.push({
                    key: " ",
                    value: "虚拟代理"
                  });
                  for (let i = 0; i < response.data.length; i++) {
                    _this.agentIds.push({
                      key: response.data[i].agentCode,
                      value: response.data[i].agentName
                    });
                  }
                }

              }
            });
          },
          addFile: function () {
            const newObject = {};
            newObject.pathName = "";
            newObject.remark = "";
            newObject.fileId = "";
            this.filDatas.push(newObject);

          },
          deleteFile: function () {
            var _this = this;
            let selectDatas = _this.$refs.refFiletab.selections;

            for (let jdx = _this.filDatas.length - 1; jdx >= 0; jdx--) {
              for (let idx = 0; selectDatas.length > idx; idx++) {
                if (_this.filDatas[jdx] == selectDatas[idx]) {
                  this.filDatas.splice(jdx, 1);
                  break;
                }
              }
            }
          }
        },
      });
    };
  });
